package com.tanhua.dubbo.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.SoulQuestionMapper;
import com.tanhua.common.pojo.SoulQuestion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName: SoulQuestionService
 * @Author:王晨晗
 * @Description: 问卷问题业务层
 * @Date: 2022/01/10/17:09
 */
@Service
public class SoulQuestionService {
    @Autowired
    private SoulQuestionMapper soulQuestionMapper;

    /**
     * @description 根据问卷id 查询问卷的题目
     * @param id
     * @return
     */
    public List<SoulQuestion> findById(Long id){
        //创建查询对象
        QueryWrapper<SoulQuestion> wrapper = new QueryWrapper<>();
        //构建查询条件
        wrapper.eq("questionnaire_id",id);
        //获取到该问卷的题目集合 并返回
        return soulQuestionMapper.selectList(wrapper);
    }

    /**
     * @description 根据题目id获取问卷id
     * @param questionId
     * @return
     */
    public Long getQuestionnaireId(Long questionId){
        //根据id进行查询, 获取问题对象
        SoulQuestion soulQuestion = soulQuestionMapper.selectById(questionId);
        //根据问题对象获取到该问题对应的问卷
        return soulQuestion.getQuestionnaireId();
    }

}
